package cn.ll.dao;
 
import org.hibernate.*;
import org.hibernate.cfg.*;
import org.springframework.orm.hibernate3.HibernateTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
 
public class HibernateUtil {
 
    private static final SessionFactory sessionFactory;
    private static PlatformTransactionManager tm = null;
    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
        	Configuration config = new AnnotationConfiguration();
        	sessionFactory = config.configure().buildSessionFactory();
        	setTm(new HibernateTransactionManager(sessionFactory)); 
        	//sessionFactory = new AnnotationConfiguration().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
 
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

	public static void setTm(PlatformTransactionManager tm) {
		HibernateUtil.tm = tm;
	}

	public static PlatformTransactionManager getTm() {
		return tm;
	}
 
}